package edu.towson.cosc.cosc455.nbedard.markdowncompiler;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;

public class MyCompilerClass {

	static String inputLoc = "C:\\Users\\Nick\\workspace\\Compiler\\src\\files\\test6.mkd";
	static String outputLoc = "C:\\Users\\Nick\\workspace\\Compiler\\src\\files\\outTest.html";
	static String token;
	static PrintWriter output;
	static BufferedReader input;
	
	public static void main(String[] args) throws CompilerException{
		File f = new File(inputLoc);
		MyLexicalAnalyzer lexer = new MyLexicalAnalyzer();
		MySyntaxAnalyzer msa = new MySyntaxAnalyzer();
		MySemanticAnalyzer semantics = new MySemanticAnalyzer();
		MyCompilerClass mcc = new MyCompilerClass();
		token = "";
		
		try{
			output = new PrintWriter(new FileWriter(outputLoc));
		}catch(Exception e){
			System.out.print(e.toString());
		}
		
		try{
			input = new BufferedReader(new FileReader(inputLoc));
		}catch(Exception e){
			System.out.print(e.toString());
		}
		
		System.out.println("Loading files");
		
		
		//1. check to make sure args
		//2. check to make sure the file has a mkd extension --> endsWith(".mkd")
		if(!f.getName().endsWith(".mkd")){
			String message = "The file must be a markdown file with a .mkd extension.";
			throw new CompilerException(message);
		}
		//3. inits
		//4. call the lexical analyzer to get the first token set
	    lexer.getNextToken();
		//5. call the start state of the parse, i.e., document()
		msa.document();
		
		// ... lexer and parser does its thing
		
		//6. call the semantic analyzer
		//7. write the output file to html
		semantics.convertToHTML(MySyntaxAnalyzer.parseTree);
		//8. clean up
		MySyntaxAnalyzer.parseTree.clear();
		MySemanticAnalyzer.varTree.clear();
		try {
			input.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		output.close();
		
		
	}
}
